
<html>
<head>
    <meta charset="utf-8">

    <style>
        .ct{
            width: 910px;
            margin: auto;
        }
        .main{
            float: left;
            width: 450px;
            height: 300px;
            border: 1px solid #ccc;
        }
        .main input{
            margin: 20px;
            width: 300px;
        }
        .iframe{
            float: right;
        }

        iframe{
            width: 450px;
            height: 300px;
            border: 1px dashed #ccc;
        }
    </style>
</head>
<div class="ct">
    <h1>使用降域实现跨域</h1>
    <div class="main">
        <input type="text" placeholder="http://a.zero.com:8080/a.iframe.html">
    </div>

    <iframe src="http://b.zero.com:8080/b.iframe.html" frameborder="0" ></iframe>

</div>


<script>

    // vim /etc/hosts
    // a.zero.com b.zero.com zero.com 都解析到 127.0.0.1
    document.querySelector('.main input').addEventListener('input', function(){
        console.log(this.value);
        window.frames[0].document.querySelector('input').value = this.value;
    })

    // 当前页面访问地址为 URL: http://a.zero.com:8080/a.iframe..html
    // 要通过 a.zero.com 域名访问才可以降域，127.0.0.1 访问无法降域
    document.domain = 'zero.com'



</script>
</html>


